<template>
 <div class="item-code-container">
    <div class="fixed">
        <div class="iconfont icon-xiaoxi"></div>
        <div class="iconfont icon-erweima " v-on:mouseenter="visible" @mouseleave="invisible"></div>
        <div class="iconfont icon-top" v-show="gotop" @click="toTop"></div>
    </div>
    <div class="code">
          <img src="@/assets/code3.png" alt="" v-show="showCode">
    </div>
  </div>
</template>

<script>
export default {
    data() {
    return {
      gotop: true,
      showCode:false
    };
  },
  mounted() {
    window.addEventListener("scroll", this.handleScroll, true);
  },
  methods: {
    handleScroll() {
       let scrolltop = document.documentElement.scrollTop || document.body.scrollTop;
      scrolltop > 30 ? (this.gotop = true) : (this.gotop = true);
    },
    toTop() {
      
      let top = document.documentElement.scrollTop || document.body.scrollTop;
      const timeTop = setInterval(() => {
        document.body.scrollTop = document.documentElement.scrollTop = top -= 50;
        if (top <= 0) {
          clearInterval(timeTop);
        }
      }, 10);
    },
    visible:function(){
            this.showCode = true;
        },
        invisible:function(){
            this.showCode = false;
        }
  }
}
</script>

<style lang="less">
.item-code-container{
   position: fixed;
   top:75%;
   right: 150px;
   z-index: 748943649;
.fixed{
    border-radius:3px;
    border: 1px solid #CCC;
    div{
      padding: 3px;
      border-bottom: 1px solid #CCC;
    }
    div:hover{
      background: #e44f50;
    }
    .iconfont {
        font-size: 40px;
        color: #fff;
        background: #CCC;
  }

 }
 .code{
   position: absolute;
   top:30px;
   right: -100px;
 }
}
</style>